public class Expression
{
	DataInfo dataInfo;
	
	private CondAndExpression condAndExpr;
	private int op;
	private Expression expr;
	
	public Expression()
	{
		
	}
	public Expression (CondAndExpression condAndExpr, int op, Expression expr, DataInfo dataInfo)
	{
		this.condAndExpr = condAndExpr;
		this.op = op;
		this.expr = expr;
		
		this.dataInfo = dataInfo;
	}
	
	public String toString()
	{

		String ret = "Expression\n";

		String s = "";
		s += "| " + condAndExpr.toString();

		if( expr != null )
		{
			s += "| " + " ||(OR)\n";
			s += "| " + expr.toString();
		}

		for( String st : s.split( "\n" ) )
			ret += "| " + st + "\n";

		return ret;

	}
	
	public String getType() throws SemanticException {
		
		if(expr != null)
			return("boolean");
		return(condAndExpr.getType());
		
	}
	
	public void check() throws SemanticException {
		
		if(expr != null){
			
			if(!expr.getType().equalsIgnoreCase("boolean") || !condAndExpr.getType().equalsIgnoreCase("boolean"))
			{
				String details = "One of the children of the conditional expression is not boolean.";
				if( dataInfo != null )
					throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
				else
					throw new SemanticException( details );
				
			}
			condAndExpr.check();
			expr.check();
			
		}else{
			
			condAndExpr.check();
			
		}
		
	}

}
